package cn.com.nes.site.entity.em.crm.saleorder;

import cn.com.nes.common.exception.NoSuchEnumException;

import java.util.HashMap;
import java.util.Map;

/**
 * 销售订单支付方式 枚举
 *  值域对应 t_param 表 param_type = 306
 */
public enum SaleOrderPayModelEnum {

    CASH(0, "现金"),
    PAIED_AFTER_INSTALL(1, "先安后付"),
    ;

    SaleOrderPayModelEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    private int key;
    private String value;

    public int getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public static SaleOrderPayModelEnum getEnum(String key) {
        Map<String, SaleOrderPayModelEnum> map = new HashMap<>();
        for (SaleOrderPayModelEnum saleOrderPayModelEnum : values()) {
            map.put(String.valueOf(saleOrderPayModelEnum.getKey()), saleOrderPayModelEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的支付方式");
        }
        return map.get(String.valueOf(key));
    }
}
